function addTiem(time) {
    if (time <= 9) {
        return "0" + time;
    }
    return time;
}

function time12() {
    var d = new Date();
    var hour = d.getHours();
    if (hour <= 12) {
        return "上午" + hour;
    } else {
        hour = hour - 12;
        return "下午" + hour;
    }
}

function amAndPm() {
    var d = new Date();
    var hour = d.getHours();
    if (hour > 12) {
        return "下午";
    } else {
        return "上午";
    }
}

function showTime() {
    var time = new Date();
    var hour = time.getHours();
    var min = time.getMinutes();
    var se = time.getSeconds();
    var tm = document.getElementById("time");
//	 tm.innerHTML=amAndPm()+addTiem(hour)+":"+addTiem(min)+":"+addTiem(se);
    tm.innerHTML = time12() + ":" + addTiem(min) + ":" + addTiem(se);
}

function showDay() {
    var d = new Date();
    var year = d.getFullYear();
    var month = d.getMonth() + 1;
    var date = d.getDate();
    var id = document.getElementById("day");
    var week = d.getDay();
    var weekend = new Array("星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
    id.innerHTML = year + "年" + month + "月" + date + "日&nbsp;&nbsp;&nbsp" + weekend[week];
}

// 计算到期日
// @param d1：开卡日
// @param d2：会员卡
// @param d3：优惠活动
// return: 到期日 格式：yyyy-MM-dd
function getEndTime(d1, d2, d3) {
    var starttime = new Date(d1);
    var a = Number(d2.find("option:selected").attr("op"))
    var b = Number(d3.find("option:selected").attr("ob"))
    if (Number(d2.find("option:selected").attr("op")) == null) {
        a = 0;
    }
    if (Number(d3.find("option:selected").attr("ob")) == null) {
        b = 0;
    }
    starttime.setMonth(starttime.getMonth() + a + b);
    return starttime.getFullYear() + '-' + getNowFormatDate((starttime.getMonth() + 1)) + '-' + getNowFormatDate(starttime.getDate());

}

// 个位数的日期前面加0
function getNowFormatDate(s) {
    return s < 10 ? '0' + s : s;
}